package com.study.algorithm.niuke.huawei.testquestionsone;

import java.util.Scanner;

public class ExchangeWater {

    public static void main(String[] args) {
        System.out.print("请输入空瓶数：");
        Scanner scanner = new Scanner(System.in);
        ExchangeWater exchangeWater = new ExchangeWater();

        while (scanner.hasNext()) {
            int empty = scanner.nextInt();
            int exchange = exchangeWater.computerMaxCount(empty);
            System.out.println(String.format("使用%d个空瓶最多兑换%d瓶水", empty, exchange));

        }
    }

    public int computerMaxCount(int empty) {

        int exchangeCount = 0;
        int exchangeRate = 3;
        int remain = empty;
        while (remain >= 3) {
            int currExchange = remain / exchangeRate;
            remain = (remain % exchangeRate) + currExchange;
            exchangeCount += currExchange;
        }
        if (remain == 2) {
            exchangeCount++;
        }

        return exchangeCount;

    }

    public int getMaxFull(int full, int exchangeRate) {
        return full / exchangeRate;
    }

}
